#!/bin/bash
# -*- coding: utf-8 -*-


# ------------------------ 基础写法1 ---------------------
# red_ball = []
# blue_ball = []

#
# print('双色球作业'.center(40, '-'))
# # 选择红色球
# count = 1
# while True:
#     ball = input(f'请选择第[{count}]个红色球: ').strip()
#     if ball.isdecimal():  # 必须是数字
#         int_ball = int(ball)
#         if 1 <= int_ball <= 32:
#             if int_ball in red_ball:
#                 print('该球号已存在!')
#             else:
#                 red_ball.append(int_ball)
#                 count += 1
#         else:
#             print('选择的球号范围必须是1-32')
#     else:
#         print('必须是数字!')
#     if count > 6:
#         break
#
# # 选择篮色球
# count = 1
# while True:
#     ball = input(f'请选择第[{count}]个蓝色球: ').strip()
#     if ball.isdecimal():  # 必须是数字
#         int_ball = int(ball)
#         if 1 <= int_ball <= 16:
#             if int_ball in blue_ball:
#                 print('该球号已存在!')
#             else:
#                 blue_ball.append(int_ball)
#                 count += 1
#         else:
#             print('选择的球号范围必须是1-16')
#     else:
#         print('必须是数字!')
#     if count > 2:
#         break
# print("您选择的红色球为: ", red_ball)
# print("您选择的蓝色球为: ", blue_ball)

# ------------------------ 基础写法2 ---------------------

# red_ball = []
# blue_ball = []
#
# print('双色球作业'.center(40, '-'))
# # 选择红色球
# count = 1
# while count < 7:
#     ball = input(f'请选择第[{count}]个红色球: ').strip()
#     if ball.isdecimal():  # 必须是数字
#         int_ball = int(ball)
#         if 1 <= int_ball <= 32:
#             if int_ball in red_ball:
#                 print('该球号已存在!')
#             else:
#                 red_ball.append(int_ball)
#                 count += 1
#         else:
#             print('选择的球号范围必须是1-32')
#     else:
#         print('必须是数字!')
#
# # 选择篮色球
# count = 1
# while count < 3:
#     ball = input(f'请选择第[{count}]个蓝色球: ').strip()
#     if ball.isdecimal():  # 必须是数字
#         int_ball = int(ball)
#         if 1 <= int_ball <= 16:
#             if int_ball in blue_ball:
#                 print('该球号已存在!')
#             else:
#                 blue_ball.append(int_ball)
#                 count += 1
#         else:
#             print('选择的球号范围必须是1-16')
#     else:
#         print('必须是数字!')
# print("您选择的红色球为: ", red_ball)
# print("您选择的蓝色球为: ", blue_ball)


# ------------------------ 扩展，使用一个while循环（伪）,写法1 ---------------------

# red_ball = []
# blue_ball = []
#
# print('双色球作业'.center(40, '-'))
#
# while True:
#     # 选择红色球
#     count = 1
#     while count < 7:
#         ball = input(f'请选择第[{count}]个红色球: ').strip()
#         if ball.isdecimal():  # 必须是数字
#             int_ball = int(ball)
#             if 1 <= int_ball <= 32:
#                 if int_ball in red_ball:
#                     print('该球号已存在!')
#                 else:
#                     red_ball.append(int_ball)
#                     count += 1
#             else:
#                 print('选择的球号范围必须是1-32')
#         else:
#             print('必须是数字!')
#     # 选择篮色球
#     count = 1
#     while count < 3:
#         ball = input(f'请选择第[{count}]个蓝色球: ').strip()
#         if ball.isdecimal():  # 必须是数字
#             int_ball = int(ball)
#             if 1 <= int_ball <= 16:
#                 if int_ball in blue_ball:
#                     print('该球号已存在!')
#                 else:
#                     blue_ball.append(int_ball)
#                     count += 1
#             else:
#                 print('选择的球号范围必须是1-16')
#         else:
#             print('必须是数字!')
#     break
# print("您选择的红色球为: ", red_ball)
# print("您选择的蓝色球为: ", blue_ball)


# ------------------------ 扩展，使用一个while循环,写法2 ---------------------

# red_ball = []
# blue_ball = []
#
# print('双色球作业'.center(40, '-'))
# count = 1
# while True:
#     # 选择红色球
#     if count < 7:
#         ball = input(f'请选择第[{count}]个红色球: ').strip()
#         if ball.isdecimal():  # 必须是数字
#             int_ball = int(ball)
#             if 1 <= int_ball <= 32:
#                 if int_ball in red_ball:
#                     print('该球号已存在!')
#                 else:
#                     red_ball.append(int_ball)
#                     count += 1
#             else:
#                 print('选择的球号范围必须是1-32')
#         else:
#             print('必须是数字!')
#     # 选择篮色球
#     else:
#         ball = input(f'请选择第[{count - 6}]个蓝色球: ').strip()
#         if ball.isdecimal():  # 必须是数字
#             int_ball = int(ball)
#             if 1 <= int_ball <= 16:
#                 if int_ball in blue_ball:
#                     print('该球号已存在!')
#                 else:
#                     blue_ball.append(int_ball)
#                     count += 1
#                     if count > 8:
#                         break
#             else:
#                 print('选择的球号范围必须是1-16')
#         else:
#             print('必须是数字!')
#
# print("您选择的红色球为: ", red_ball)
# print("您选择的蓝色球为: ", blue_ball)


# ------------------------ 扩展,控制台输出带有颜色的字体设置 ---------------------
# 控制台输出带有颜色的字体设置： # https://www.cnblogs.com/Neeo/articles/8650129.html
red_ball = []
blue_ball = []

print('双色球作业'.center(40, '-'))
count = 1
while True:
    # 选择红色球
    if count < 7:
        ball = input(f'\033[31;1m请选择第[{count}]个红色球: \033[0m').strip()
        if ball.isdecimal():  # 必须是数字
            int_ball = int(ball)
            if 1 <= int_ball <= 32:
                if int_ball in red_ball:
                    print('该球号已存在!')
                else:
                    red_ball.append(int_ball)
                    count += 1
            else:
                print('选择的球号范围必须是1-32')
        else:
            print('必须是数字!')
    # 选择篮色球
    else:
        ball = input(f'\033[34;1m请选择第[{count - 6}]个蓝色球: \033[0m').strip()
        if ball.isdecimal():  # 必须是数字
            int_ball = int(ball)
            if 1 <= int_ball <= 16:
                if int_ball in blue_ball:
                    print('该球号已存在!')
                else:
                    blue_ball.append(int_ball)
                    count += 1
                    if count > 8:
                        break
            else:
                print('选择的球号范围必须是1-16')
        else:
            print('必须是数字!')

print("您选择的红色球为: ", red_ball)
print("您选择的蓝色球为: ", blue_ball)
